Storing a key value to a deleted row based on key range density

ABSTRACT

In an embodiment, a first key value is received. A plurality of candidate rows are found in a database table, wherein the plurality of candidate rows are deleted. For the plurality of candidate rows, a plurality of respective impacts on a plurality of respective densities of each of other key values that are stored within a first key range of the first key value are calculated. For the plurality of candidate rows, a plurality of function results of the plurality of respective impacts on the plurality of respective densities are calculated. A selected candidate row of the plurality of candidate rows with a smallest function result of the plurality of function results of the plurality of respective impacts on the plurality of respective densities is selected. The first key value is stored to the selected candidate row.

FIELD

This invention generally relates to computer database management systemsand more specifically relates to database management systems that insertkey values into available rows of a database table.

BACKGROUND

Computer systems typically comprise a combination of computer programsand hardware, such as semiconductors, transistors, chips, circuitboards, storage devices, and processors. The computer programs arestored in the storage devices and are executed by the processors.Fundamentally, computer systems are used for the storage, manipulation,and analysis of data.

One mechanism for managing data is called a database management system(DBMS) or simply a database. Many different types of databases areknown, but the most common is usually called a relational database,which organizes data in tables that have rows, which representindividual entries, tuples, or records in the database, and columns,keys, fields, or attributes, which define what is stored in each entry,tuple, or record. The data stored in the columns of the rows are knownas key values. Each table has a unique name or identifier within thedatabase and each column has a unique name within the particular table.The database also has one or more indexes, which are data structuresthat inform the DBMS of the location of a certain row in a table givenan indexed column value, analogous to a book index informing the readerof the page on which a given word appears.

SUMMARY

A method, computer-readable storage medium, and computer system areprovided. In an embodiment, a first key value is received. A pluralityof candidate rows are found in a database table, wherein the pluralityof candidate rows are deleted. For the plurality of candidate rows, aplurality of respective impacts on a plurality of respective densitiesof each of other key values that are stored within a first key range ofthe first key value are calculated. For the plurality of candidate rows,a plurality of function results of the plurality of respective impactson the plurality of respective densities are calculated. A selectedcandidate row of the plurality of candidate rows with a smallestfunction result of the plurality of function results of the plurality ofrespective impacts on the plurality of respective densities is selected.The first key value is stored to the selected candidate row.

BRIEF DESCRIPTION OF THE SEVERAL VIEWS OF THE DRAWINGS

FIG. 1 depicts a high-level block diagram of an example system forimplementing an embodiment of the invention.

FIG. 2 depicts a block diagram of an example database management system,according to an embodiment of the invention.

FIG. 3 depicts a block diagram of an example database, according to anembodiment of the invention.

FIG. 4 depicts a block diagram of an example data structure for a symboltable, according to an embodiment of the invention.

FIG. 5 depicts a block diagram of an example data structure for anothersymbol table, according to an embodiment of the invention.

FIG. 6 depicts a block diagram of an example data structure for anothersymbol table, according to an embodiment of the invention.

FIG. 7 depicts a block diagram of an example database before insertionof a value, according to an embodiment of the invention.

FIG. 8 depicts a block diagram of an example data structure for a symboltable before insertion of a value into the database, according to anembodiment of the invention.

FIG. 9 depicts a block diagram of an example database after insertion ofa value, according to an embodiment of the invention.

FIG. 10 depicts a block diagram of an example data structure for asymbol table after insertion of a value into the database, according toan embodiment of the invention.

FIG. 11 depicts a flowchart of example processing for an insert orupdate command, according to an embodiment of the invention.

FIG. 12 depicts a flowchart of example processing for reorganizing adatabase table, according to an embodiment of the invention.

It is to be noted, however, that the appended drawings illustrate onlyexample embodiments of the invention, and are therefore not considered alimitation of the scope of other embodiments of the invention.

DETAILED DESCRIPTION

Referring to the Drawings, wherein like numbers denote like partsthroughout the several views, FIG. 1 depicts a high-level block diagramrepresentation of a server computer system 100 connected to a clientcomputer system 132 via a network 130, according to an embodiment of thepresent invention. The terms “server” and “client” are used herein forconvenience only, and in various embodiments a computer system thatoperates as a client computer in one environment may operate as a servercomputer in another environment, and vice versa. The mechanism andapparatus of embodiments of the present invention apply equally to anyappropriate computing system.

The major components of the server computer system 100 comprise one ormore processors 101, memory 102, a terminal interface unit 111, astorage interface unit 112, an I/O (Input/Output) device interface unit113, and a network interface unit 114, all of which are communicativelycoupled, directly or indirectly, for inter-component communication via amemory bus 103, an I/O bus 104, and an I/O bus interface unit 105.

The server computer system 100 contains one or more general-purposeprogrammable central processing units (CPUs) 101A, 101B, 101C, and 101D,herein generically referred to as the processor 101. In an embodiment,the server computer system 100 contains multiple processors typical of arelatively large system; however, in another embodiment the servercomputer system 100 may alternatively be a single CPU system. Eachprocessor 101 executes instructions stored in the memory 102 and maycomprise one or more levels of on-board cache.

In an embodiment, the memory 102 may comprise a random-accesssemiconductor memory, storage device, or storage medium (either volatileor non-volatile) for storing or encoding data and programs. In anotherembodiment, the memory 102 represents the entire virtual memory of theserver computer system 100, and may also include the virtual memory ofother computer systems coupled to the server computer system 100 orconnected via the network 130. The memory 102 is conceptually a singlemonolithic entity, but in other embodiments the memory 102 is a morecomplex arrangement, such as a hierarchy of caches and other memorydevices. For example, memory may exist in multiple levels of caches, andthese caches may be further divided by function, so that one cache holdsinstructions while another holds non-instruction data, which is used bythe processor or processors. Memory may be further distributed andassociated with different CPUs or sets of CPUs, as is known in any ofvarious so-called non-uniform memory access (NUMA) computerarchitectures.

The memory 102 stores or encodes a database management system (DBMS)150, an insert or update command 158, and an application 160. Althoughthe database management system 150, the insert/update command 158, andthe application 160 are illustrated as being contained within the memory102 in the server computer system 100, in other embodiments some or allof them may be on different computer systems and may be accessedremotely, e.g., via the network 130. For example, the databasemanagement system 150, the insert/update command 158, and theapplication 160 may be stored in memory in the client computer system132. The server computer system 100 may use virtual addressingmechanisms that allow the programs of the server computer system 100 tobehave as if they only have access to a large, single storage entityinstead of access to multiple, smaller storage entities. Thus, while thedatabase management system 150, the insert/update command 158, and theapplication 160 are illustrated as being contained within the memory102, these elements are not necessarily all completely contained in thesame storage device at the same time. Further, although the databasemanagement system 150, the insert/update command 158, and theapplication 160 are illustrated as being separate entities, in otherembodiments some of them, portions of some of them, or all of them maybe packaged together.

In an embodiment, the DBMS 150 and/or the application 160 compriseinstructions or statements that execute on the processor 101 orinstructions or statements that are interpreted by instructions orstatements that execute on the processor 101, to carry out the functionsas further described below with reference to FIGS. 2, 3, 4, 5, 6, 7, 8,9, 10, 11, and 12. In another embodiment, the DBMS 150 and/or theapplication 160 are implemented in hardware via semiconductor devices,chips, logical gates, circuits, circuit cards, and/or other physicalhardware devices in lieu of, or in addition to, a processor-basedsystem. In an embodiment, the DBMS 150 and/or the application 160comprise data, in addition to instructions or statements.

The memory bus 103 provides a data communication path for transferringdata among the processor 101, the memory 102, and the I/O bus interfaceunit 105. The I/O bus interface unit 105 is further coupled to the I/Obus 104 for transferring data to and from the various I/O units. The I/Obus interface unit 105 communicates with multiple I/O interface units111, 112, 113, and 114, which are also known as I/O processors (IOPs) orI/O adapters (IOAs), through the system I/O bus 104.

The I/O interface units support communication with a variety of storageand I/O devices. For example, the terminal interface unit 111 supportsthe attachment of one or more user I/O devices 121, which may compriseuser output devices (such as a video display device, speaker, and/ortelevision set) and user input devices (such as a keyboard, mouse,keypad, touchpad, trackball, buttons, light pen, or other pointingdevice). A user may manipulate the user input devices using a userinterface, in order to provide input data and commands to the user I/Odevice 121 and the server computer system 100, and may receive outputdata via the user output devices. For example, a user interface may bepresented via the user I/O device 121, such as displayed on a displaydevice, played via a speaker, or printed via a printer.

The storage interface unit 112 supports the attachment of one or moredisk drives or direct access storage devices 125 (which are typicallyrotating magnetic disk drive storage devices, although they couldalternatively be other storage devices, including arrays of disk drivesconfigured to appear as a single large storage device to a hostcomputer). In another embodiment, the storage device 125 may beimplemented via any type of secondary storage device. The contents ofthe memory 102, or any portion thereof, may be stored to and retrievedfrom the storage device 125, as needed. The I/O device interface unit113 provides an interface to any of various other input/output devicesor devices of other types, such as printers or fax machines. The networkinterface unit 114 provides one or more communications paths from theserver computer system 100 to other digital devices and client computersystems 132; such paths may comprise, e.g., one or more networks 130.

Although the memory bus 103 is shown in FIG. 1 as a relatively simple,single bus structure providing a direct communication path among theprocessors 101, the memory 102, and the I/O bus interface unit 105, infact the memory bus 103 may comprise multiple different buses orcommunication paths, which may be arranged in any of various forms, suchas point-to-point links in hierarchical, star or web configurations,multiple hierarchical buses, parallel and redundant paths, or any otherappropriate type of configuration. Furthermore, while the I/O businterface unit 105 and the I/O bus 104 are shown as single respectiveunits, the server computer system 100 may, in fact, contain multiple I/Obus interface units 105 and/or multiple I/O buses 104. While multipleI/O interface units are shown, which separate the system I/O bus 104from various communications paths running to the various I/O devices, inother embodiments some or all of the I/O devices are connected directlyto one or more system I/O buses.

In various embodiments, the server computer system 100 is a multi-usermainframe computer system, a single-user system, or a server computer orsimilar device that has little or no direct user interface, but receivesrequests from other computer systems (clients). In other embodiments,the server computer system 100 is implemented as a desktop computer,portable computer, laptop or notebook computer, tablet computer, pocketcomputer, telephone, smart phone, pager, automobile, teleconferencingsystem, appliance, or any other appropriate type of electronic device.

The network 130 may be any suitable network or combination of networksand may support any appropriate protocol suitable for communication ofdata and/or code to/from the server computer system 100 and the clientcomputer system 132. In various embodiments, the network 130 mayrepresent a storage device or a combination of storage devices, eitherconnected directly or indirectly to the server computer system 100. Inanother embodiment, the network 130 may support wireless communications.In another embodiment, the network 130 may support hard-wiredcommunications, such as a telephone line or cable. In anotherembodiment, the network 130 may be the Internet and may support IP(Internet Protocol). In another embodiment, the network 130 isimplemented as a local area network (LAN) or a wide area network (WAN).In another embodiment, the network 130 is implemented as a hotspotservice provider network. In another embodiment, the network 130 isimplemented an intranet. In another embodiment, the network 130 isimplemented as any appropriate cellular data network, cell-based radionetwork technology, or wireless network. In another embodiment, thenetwork 130 is implemented as any suitable network or combination ofnetworks. Although one network 130 is shown, in other embodiments anynumber of networks (of the same or different types) may be present.

The client computer system 132 may comprise some or all of the hardwareand/or computer program elements of the server computer system 100. Inan embodiment, the application 160 may be stored in a storage device atthe client computer system 132, may execute on a processor at the clientcomputer system 132, and may send the insert/update commands 158 to theserver computer system 100 via the network 130.

FIG. 1 is intended to depict the representative major components of theserver computer system 100, the network 130, and the client computersystem 132. But, individual components may have greater complexity thanrepresented in FIG. 1, components other than or in addition to thoseshown in FIG. 1 may be present, and the number, type, and configurationof such components may vary. Several particular examples of suchadditional complexity or additional variations are disclosed herein;these are by way of example only and are not necessarily the only suchvariations. The various program components illustrated in FIG. 1 andimplementing various embodiments of the invention may be implemented ina number of manners, including using various computer applications,routines, components, programs, objects, modules, data structures, etc.,and are referred to hereinafter as “computer programs,” or simply“programs.”

The computer programs comprise one or more instructions or statementsthat are resident at various times in various memory and storage devicesin the server computer system 100 and that, when read and executed byone or more processors in the server computer system 100 or wheninterpreted by instructions that are executed by one or more processors,cause the server computer system 100 to perform the actions necessary toexecute steps or elements comprising the various aspects of embodimentsof the invention. Aspects of embodiments of the invention may beembodied as a system, method, or computer program product. Accordingly,aspects of embodiments of the invention may take the form of an entirelyhardware embodiment, an entirely program embodiment (including firmware,resident programs, micro-code, etc., which are stored in a storagedevice) or an embodiment combining program and hardware aspects that mayall generally be referred to herein as a “circuit,” “module,” or“system.” Further, embodiments of the invention may take the form of acomputer program product embodied in one or more computer-readablemedium(s) having computer-readable program code embodied thereon.

Any combination of one or more computer-readable medium(s) may beutilized. The computer-readable medium may be a computer-readable signalmedium or a computer-readable storage medium. A computer-readablestorage medium, may be, for example, but not limited to, an electronic,magnetic, optical, electromagnetic, infrared, or semiconductor system,apparatus, or device, or any suitable combination of the foregoing. Morespecific examples (an non-exhaustive list) of the computer-readablestorage media may comprise: an electrical connection having one or morewires, a portable computer diskette, a hard disk (e.g., the storagedevice 125), a random access memory (RAM) (e.g., the memory 102), aread-only memory (ROM), an erasable programmable read-only memory(EPROM) or Flash memory, an optical fiber, a portable compact discread-only memory (CD-ROM), an optical storage device, a magnetic storagedevice, or any suitable combination of the foregoing. In the context ofthis document, a computer-readable storage medium may be any tangiblemedium that can contain, or store, a program for use by or in connectionwith an instruction execution system, apparatus, or device.

A computer-readable signal medium may comprise a propagated data signalwith computer-readable program code embodied thereon, for example, inbaseband or as part of a carrier wave. Such a propagated signal may takeany of a variety of forms, including, but not limited to,electro-magnetic, optical, or any suitable combination thereof. Acomputer-readable signal medium may be any computer-readable medium thatis not a computer-readable storage medium and that communicates,propagates, or transports a program for use by, or in connection with,an instruction execution system, apparatus, or device. Program codeembodied on a computer-readable medium may be transmitted using anyappropriate medium, including but not limited to, wireless, wire line,optical fiber cable, Radio Frequency, or any suitable combination of theforegoing.

Computer program code for carrying out operations for aspects ofembodiments of the present invention may be written in any combinationof one or more programming languages, including object orientedprogramming languages and conventional procedural programming languages.The program code may execute entirely on the user's computer, partly ona remote computer, or entirely on the remote computer or server. In thelatter scenario, the remote computer may be connected to the user'scomputer through any type of network, including a local area network(LAN) or a wide area network (WAN), or the connection may be made to anexternal computer (for example, through the Internet using an InternetService Provider).

Aspects of embodiments of the invention are described below withreference to flowchart illustrations and/or block diagrams of methods,apparatus (systems), and computer program products. Each block of theflowchart illustrations and/or block diagrams, and combinations ofblocks in the flowchart illustrations and/or block diagrams may beimplemented by computer program instructions embodied in acomputer-readable medium. These computer program instructions may beprovided to a processor of a general purpose computer, special purposecomputer, or other programmable data processing apparatus to produce amachine, such that the instructions, which execute via the processor ofthe computer or other programmable data processing apparatus, createmeans for implementing the functions/acts specified by the flowchartand/or block diagram block or blocks. These computer programinstructions may also be stored in a computer-readable medium that candirect a computer, other programmable data processing apparatus, orother devices to function in a particular manner, such that theinstructions stored in the computer-readable medium produce an articleof manufacture, including instructions that implement the function/actspecified by the flowchart and/or block diagram block or blocks.

The computer programs defining the functions of various embodiments ofthe invention may be delivered to a computer system via a variety oftangible computer-readable storage media that may be operatively orcommunicatively connected (directly or indirectly) to the processor orprocessors. The computer program instructions may also be loaded onto acomputer, other programmable data processing apparatus, or other devicesto cause a series of operational steps to be performed on the computer,other programmable apparatus, or other devices to produce acomputer-implemented process, such that the instructions, which executeon the computer or other programmable apparatus, provide processes forimplementing the functions/acts specified in the flowcharts and/or blockdiagram block or blocks.

The flowchart and the block diagrams in the figures illustrate thearchitecture, functionality, and operation of possible implementationsof systems, methods, and computer program products, according to variousembodiments of the present invention. In this regard, each block in theflowcharts or block diagrams may represent a module, segment, or portionof code, which comprises one or more executable instructions forimplementing the specified logical function(s). In some embodiments, thefunctions noted in the block may occur out of the order noted in thefigures. For example, two blocks shown in succession may, in fact, beexecuted substantially concurrently, or the blocks may sometimes beexecuted in the reverse order, depending upon the functionalityinvolved. Each block of the block diagrams and/or flowchartillustration, and combinations of blocks in the block diagrams and/orflow chart illustrations, can be implemented by special purposehardware-based systems that perform the specified functions or acts, incombinations of special purpose hardware and computer instructions.

Embodiments of the invention may also be delivered as part of a serviceengagement with a client corporation, nonprofit organization, governmententity, or internal organizational structure. Aspects of theseembodiments may comprise configuring a computer system to perform, anddeploying computing services (e.g., computer-readable code, hardware,and web services) that implement, some or all of the methods describedherein. Aspects of these embodiments may also comprise analyzing theclient company, creating recommendations responsive to the analysis,generating computer-readable code to implement portions of therecommendations, integrating the computer-readable code into existingprocesses, computer systems, and computing infrastructure, metering useof the methods and systems described herein, allocating expenses tousers, and billing users for their use of these methods and systems. Inaddition, various programs described hereinafter may be identified basedupon the application for which they are implemented in a specificembodiment of the invention. But, any particular program nomenclaturethat follows is used merely for convenience, and thus embodiments of theinvention are not limited to use solely in any specific applicationidentified and/or implied by such nomenclature. The exemplaryenvironments illustrated in FIG. 1 are not intended to limit the presentinvention. Indeed, other alternative hardware and/or programenvironments may be used without departing from the scope of embodimentsof the invention.

FIG. 2 depicts a block diagram of an example database management system150, according to an embodiment of the invention. The DBMS 150 comprisesa parser 205, a parsed statement 210, an optimizer 215, an executionengine 220, an execution plan 225, and a database 230.

The database 230 comprises tables 235, optional indexes 240, and symboltables 260. The tables 235 organize data in rows, which representindividual entries, tuples, or records and columns, keys, fields, orattributes, which define what is stored in each row, entry, tuple, orrecord. Each table 235 has a unique name or identifier within a database230 (but not necessarily a unique name across all databases) and eachcolumn has a unique name within the particular table 235. The indexes240 are data structures that inform the DBMS 150 of the location of acertain row in a table 235, in response to the indexes 240 receiving anindexed column value.

The parser 205 in the DBMS 150 receives the insert/update command 158from the application 160. The insert command 158 requests that the DBMS150 insert or store a row or rows of data to a table or tables 235. Inanother embodiment, an update command 158 requests that the DBMS 150modify the value of an existing row in the table 235. The parser 205generates a parsed statement 210 from the insert/update command 158,which the parser 205 sends to the optimizer 215. The optimizer 215performs optimization on the parsed statement 210. As a part ofoptimization, the optimizer 215 generates one or more execution plans225.

The execution engine 220 reads the execution plan 225 and executes theselected execution plan 225 to insert or update the data specified bythe insert/update command 158. The execution engine 220 optionally usingthe indexes 240, in order to find the appropriate row of data in thetables 235 to modify or update. The optimizer 215 and/or the executionengine 220 use the symbol tables 260 to determine a deleted, free, oravailable row, in which to insert the data into the tables 235 and tomove rows within the tables 235.

FIG. 3 depicts a block diagram of an example database 230-1, accordingto an embodiment of the invention. The database 230-1 is an example of,and is generically referred to by, the database 230 (FIG. 2). Theexample database 230-1 comprises an example table X 235, which comprisesexample keys, fields, or columns 340 and 342, each of which stores rowsof key values at relative record numbers (RRNs). The RRNs are theaddress or offset of their respective rows from the start of the table X235, in sequential address order. In various embodiments, the RRNs maybe present as a field or fields in the table X 235 or may exist asaddresses or offsets of locations in memory. The key values in thecolumns that have the same RRN are in the same row and the key values inthe columns that have different RRNs are in different rows. The RRNs“49,” “50,” “51,” “52,” “53,” and “54” are deleted, free, or availablefor use and do not contain valid key values. Although the deleted RRNs“49,” “50,” “51,” “52,” “53,” and “54” are illustrated as containing nokey values (being blank), in other embodiments, they may contain data,but a flag or indicator is set to indicate that the key values aredeleted or invalid, and the rows are available or free for the DBMS 150to insert data into the deleted rows.

FIG. 4 depicts a block diagram of an example data structure for a symboltable 260-1, according to an embodiment of the invention. The symboltable 260-1 is an example of, and is generically referred to by, thesymbol table 260 (FIG. 2). The symbol table 260-1 comprises any numberof entries, each of which comprises example fields, such as the keyvalue field 410, the first RRN field 412, the last RRN field 414, thedeleted count field 416, the key count field 418, and the RRN densityfield 420.

The key value field 410, in each entry, identifies the key value in thecolumn that is assigned to the symbol table 260-1, which in this exampleis the column x.city 340. The first RRN field 412, in each entry,identifies the relative record number of the first row (in relativerecord number order) in the database table assigned to the symbol table260-1 (which in this example is the table X 235) that contains the keyvalue specified by the key value 410, in the same entry. For example, norows in the column x.city 340 prior to the first RRN 412 of “2” containthe key value “Albert Lea.” The last RRN field 414, in each entry,identifies the relative record number of the last row (in relativerecord number order) in the database table assigned to the symbol table260-1 (which in this example is the table x 235) that contains the keyvalue specified by the key value 410, in the same entry. For example, norows in the column x.city 340 after the last RRN 414 of “46” contain thekey value “Albert Lea.” Thus, the first RRN 412 and the last RRN 414specify the key range of rows in the table x 235 that may, but do notnecessarily, contain the key value specified in the same entry, and norows outside of that key range contain the key value in the key valuefield 410, in the same entry. The ranges of different key values mayoverlap, meaning that, in an embodiment, the first RRN 412 of a firstkey value may be less than the first RRN 412 of a second key value whilethe last RRN 414 of the first key value may be between the first RRN 412and the last RRN 414 of the second key value. The ranges of key valuesmay also overlap, meaning that, in an embodiment, the first RRN 412 of afirst key value may be less than the first RRN 412 of a second key valuewhile the last RRN 414 of the first key value may be greater than thelast RRN 414 of the second key value. The ranges of different key valuesmay also not overlap, meaning that the first RRN 412 and the last RRN414 of a first key value may both be less than the first RRN 412 of asecond key value. Thus, a key range for a particular key value comprisesall of the rows that comprise that particular key value plus zero, one,or more deleted (free or available) rows, plus zero, one, or more rowsthat comprise another key value or values.

The deleted count field 416 specifies the number of rows (in the columnassigned to the symbol table 260-1, which in this example is the columnx.city 340) whose relative record numbers are between the first RRN 412and the last RRN 414, in the same entry, and that are deleted, areavailable, or are free (contain no key value). The key count field 418,in each entry, specifies the number of rows (in the column assigned tothe symbol table 260-1, which in this example is the column x.city 340)whose relative record numbers are between the first RRN 412 and the lastRRN 414, in the same entry, and that contain the key value 410, in thesame entry.

The RRN density field 420, in each entry specifies the density of therows that contain the key value 410, in the same entry, within the keyrange specified by the first RRN 412 and the last RRN 414, in the sameentry. In an embodiment, the DBMS 150 calculates the RRN density 420 tobe equal to (last RRN 414−first RRN 412+1−deleted count 416)/key count418, in each entry. Thus, the RRN density 420 for a particular key value410 specified by an entry is the number of rows in the key range of thatparticular key value that contain some key value (are not deleted andcontain either the key value 410 specified by the entry or some otherkey value specified by some other entry) divided by the number of rowsin the key range that comprise the key value 410 specified by the entry.

FIG. 5 depicts a block diagram of an example data structure for anothersymbol table 260-2, according to an embodiment of the invention. Thesymbol table 260-2 is an example of, and is generically referred to by,the symbol table 260 (FIG. 2). The symbol table 260-2 comprises anynumber of entries, each of which comprises example fields, such as thekey value field 510, the first RRN field 512, the last RRN field 514,the deleted count field 516, the key count field 518, and the RRNdensity field 520.

The key value field 510, in each entry, identifies the key value in thecolumn that is assigned to the symbol table 260-2, which in this exampleis the column x.state 342. The first RRN field 512, in each entry,identifies the relative record number of the first row (in relativerecord number order) in the database table assigned to the symbol table260-2 (which in this example is the table X 235) that contains the keyvalue specified by the key value 510, in the same entry. For example, norows in the column x.state 342 prior to the first RRN 512 of “4” containthe key value “WI.” The last RRN field 514, in each entry, identifiesthe relative record number of the last row (in relative record numberorder) in the database table assigned to the symbol table 260-2 (whichin this example is the table x 235) that contains the key valuespecified by the key value 510, in the same entry. For example, no rowsin the column x.state 342 after the last RRN 514 of “5” contain the keyvalue “WI.”

The deleted count field 516 specifies the number of rows (in the columnassigned to the symbol table 260-2, which in this example is the columnx.state 342) whose relative record numbers are between the first RRN 512and the last RRN 514, in the same entry, and that are deleted, areavailable, or are free (contain no key value). The key count field 518,in each entry, specifies the number of rows (in the column assigned tothe symbol table 260-2, which in this example is the column x.state 342)whose relative record numbers are between the first RRN 512 and the lastRRN 514, in the same entry, and that contain the key value 510, in thesame entry.

The RRN density field 520, in each entry specifies the density of therows that contain the key value 510, in the same entry, within the keyrange specified by the first RRN 512 and the last RRN 514, in the sameentry. In an embodiment, the DBMS 150 calculates the RRN density 520 tobe equal to (last RRN 515−first RRN 515+1−deleted count 516)/key count518, in each entry. Thus, the RRN density 520 for a particular key value510 specified by an entry is the number of rows in the key range of thatparticular key value that contain some key value (are not deleted andcontain either the key value 510 specified by the entry or some otherkey value specified by some other entry) divided by the number of rowsin the key range that comprise the key value 510 specified by the entry.

FIG. 6 depicts a block diagram of an example data structure for a symboltable 260-3, according to an embodiment of the invention. The symboltable 260-3 is an example of, and is generically referred to by, thesymbol table 260 (FIG. 2). The symbol table 260-3 is assigned tomultiple columns of the database table x 235, which in this example arethe x.city column 340 and the x.state column 342, and a multi-key indexover both of the x.city column 340 and the x.state column 342 exists. Asymbol table 260 that is assigned to multiple columns may be useful inembodiments where a key value in one column has multiple different keyvalues in multiple rows in another column. For example, FIG. 3illustrates that the key value of “Rochester” in the x.city column 340has “MN” in the x.state column 342 in RRN “12,” but “Rochester” in thex.city column 340 has “NY” in the x.state column 342 in RRN “47.”

The symbol table 260-3 comprises any number of entries, each of whichcomprises example fields, such as the key values field 610, the firstRRN field 612, the last RRN field 614, the deleted count field 616, thekey count field 618, and the RRN density field 620.

The key values field 610, in each entry, identify the key values in thecolumns that are assigned to the symbol table 260-3, which in thisexample are the columns x.city 340 and the column x.state 342. The firstRRN field 612, in each entry, identifies the relative record number ofthe first row (in relative record number order) in the database tableassigned to the symbol table 260-3 (which in this example is the table X235) that contains the key values specified by the key values 610, inthe columns assigned to the symbol table 260-3, in the same entry. Forexample, no rows in the table X 235 prior (in RRN order) to the firstRRN 612 of “16” contain both the key value “Rochester” in the x.citycolumn 340 and the key value “MN” in the x.state column 342. The lastRRN field 614, in each entry, identifies the relative record number ofthe last row (in relative record number order) in the database tableassigned to the symbol table 260-3 (which in this example is the table X235) that contains the key values specified by the key values 610, inthe columns assigned to the symbol table 260-3, in the same entry. Forexample, no rows in the table X 235 after (in RRN order) the last RRN614 of “47” contain both the key value “Rochester” in the x.city column340 and the key value “MN” in the x.state column 342.

The deleted count field 616 specifies the number of rows (in the columnsassigned to the symbol table 260-3, which in this example are the columnx.city 340 and the column x.state 342) whose relative record numbers arebetween the first RRN 612 and the last RRN 614, in the same entry, andthat are deleted, are available, or are free (contain no valid keyvalue). The key count field 618, in each entry, specifies the number ofrows (in the columns assigned to the symbol table 260-3) whose recordnumbers are between the first RRN 612 and the last RRN 614, in the sameentry, and that contain both of the key values specified by the keyvalues 610, in the same entry.

The RRN density field 620, in each entry specifies the density of therows that contain the key values 610, in the same entry, within the keyrange specified by the first RRN 612 and the last RRN 614, in the sameentry. In an embodiment, the DBMS 150 calculates the RRN density 620 tobe equal to (last RRN 615−first RRN 615+1−deleted count 616)/key count618, in each entry. Thus, the RRN density 620 for particular key values610 specified by an entry is the number of rows in the key range of thatparticular key value that contain some key value (are not deleted andcontain either the key values 610 specified by the entry or some otherkey value specified by some other entry) divided by the number of rowsin the key range that comprise the key values 610 specified by theentry.

FIG. 7 depicts a block diagram of an example database 230-2 beforeinsertion of a value, according to an embodiment of the invention. Thedatabase 230-2 is an example of, and is generically referred to by, thedatabase 230 (FIG. 2). The example database 230-2 comprises an exampletable X 735, which comprises an example key, field, or column 740, whichstores rows of key values at relative record numbers (RRNs). The RRNsare the address or offset of their respective rows from the start of thetable X 735, in sequential address order. In various embodiments, theRRNs may be present as a field or fields in the table X 735 or may existas addresses or offsets of locations in memory. The RRNs “2,” “6,” “8,”“10,” “14,” and “18” are deleted, free, or available for use and do notcontain valid key values. Although the deleted RRNs “2,” “6,” “8,” “10,”“14,” and “18” are illustrated as containing “<del>”, in otherembodiments, they may contain data, but a flag or indicator is set toindicate that the key values are deleted or invalid, and the rows areavailable or free for the DBMS 150 to insert data into the deleted rows.

FIG. 8 depicts a block diagram of an example data structure for a symboltable 260-4 before insertion of a value into the database 230-2 (FIG.7), according to an embodiment of the invention. The symbol table 260-4is an example of, and is generically referred to by, the symbol table260 (FIG. 2). The symbol table 260-4 comprises any number of entries,such as the entries 830, 832, 834, and 836, each of which comprisesexample fields, such as the key value field 810, the first RRN field812, the last RRN field 814, the deleted count field 816, the key countfield 818, and the RRN density field 820.

The key value field 810, in each entry, identifies the key value in thecolumn that is assigned to the symbol table 260-4, which in this exampleis the column x.city 740 of FIG. 7. The first RRN field 812, in eachentry, identifies the relative record number of the first row (inrelative record number order) in the database table assigned to thesymbol table 260-4 that contains the key value specified by the keyvalue 810, in the same entry. The last RRN field 814, in each entry,identifies the relative record number of the last row (in relativerecord number order) in the database table assigned to the symbol table260-4 that contains the key value specified by the key value 810, in thesame entry. Thus, the first RRN 812 and the last RRN 814 specify the keyrange of rows in the table X 735 that may, but do not necessarily,contain the key value in the key value field 810 specified in the sameentry, and no rows outside of that key range contain the key value inthe key value field 810, in the same entry.

The deleted count field 816 specifies the number of rows (in the columnassigned to the symbol table 260-4, which in this example is the columnx.city 740) whose relative record numbers are between the first RRN 812and the last RRN 814, in the same entry, and that are deleted, areavailable, or are free (contain no valid key value). The key count field818, in each entry, specifies the number of rows (in the column assignedto the symbol table 260-4) whose relative record numbers are between thefirst RRN 812 and the last RRN 814, in the same entry, and that containthe key value specified in the key value field 810, in the same entry.

The RRN density field 820, in each entry specifies the density of therows that contain the key value in the key value field 810, in the sameentry, within the key range specified by the first RRN 812 and the lastRRN 814, in the same entry. In an embodiment, the DBMS 150 calculatesthe RRN density 820 to be equal to (the last RRN 814−the first RRN812+1−the deleted count 816)/the key count 818, in each entry. Thus, theRRN density 820 for a particular key value 810 specified by an entry isthe number of rows in the key range of that particular key value thatcontain some key value (are not deleted and contain either the key value810 specified by the entry or some other key value specified by someother entry) divided by the number of rows in the key range thatcomprise the key value 810 specified by the entry.

FIG. 9 depicts a block diagram of an example database 230-3 afterinsertion of a value “Albert Lea” into the row at RRN “10” of thedatabase 230-2 (FIG. 7), according to an embodiment of the invention.The database 230-3 comprises a table 935, comprising column 940. Inresponse to an insert command received by the DBMS 150, which requeststhat a value of “Albert Lea” be inserted into a row in the database230-2 in the column x.city 740, the DBMS 150 selects the symbol table260-4 that is assigned to the column x.city 740. The DBMS 150 thendetermines whether the deleted count 816 is greater than zero in theentry 832 that contains a key value 810 that matches the received valueof “Albert Lea.” That is, the DBMS 150 determines whether the key rangeof the received key value has any deleted rows. Since the deleted count816 for the received key value of “Albert Lea” in the entry 832 is “4,”which is greater than zero, the DBMS 150 finds all candidate rows, whichare deleted rows that are within the key range specified by the entry832. In other embodiments the DBMS 150 finds the candidate rows to beall deleted rows that are not within the key range specified by theentry 832 or selects candidate rows to be a sample of the deleted rowsthat are within the key range specified by the entry 832. In variousembodiments, the sample size is set by a designer of the DBMS 150, isreceived from the application 160, is received from the user I/O device121, or is received from the network 130. Using the example of FIGS. 7and 8, the DBMS 150 determines the candidate rows to be the rows in thex.city column 740 of the database 230-2 with RRNs of “6,” “8,” “10,” and“14” because these are the deleted rows that are within the “Albert Lea”key range, as specified by the first RRN field 812 and the last RRNfield 814 in the entry 832 with the key value 810 of “Albert Lea.”

The DBMS 150 then calculates, for each candidate row, the impact ofpotentially inserting the key value into the candidate row on the RRNdensity of each of the other key values (different from the received keyvalue) that are stored within the key range of the received key value(the key ranges of the other key values overlap the key range of thereceived key value). The DBMS 150 then selects the deleted row, intowhich the potential insertion of the received key value causes thefunction result (in various embodiments, the function result is anarithmetic or logical function result, such as a sum, a maximum, anarithmetic product, a logarithmic function, or any combination ormultiple thereof) of all the impacts on the calculated RRN densities toincrease the least.

Using the example of FIGS. 7 and 8, the DBMS 150 calculates the impactof potentially inserting the received key of “Albert Lea” into thecandidate row of RRN “6” as the potential RRN density of the “Austin”key range, as impacted by the potential insertion at RRN “6” minus thecurrent RRN density 820 of the “Austin” key range (entry 830)=(last RRNof the “Austin” key range−first RRN of the “Austin” key range+1−deletedcount of the “Austin” key range)/(key count of the “Austin” keyrange)−current density of the “Austin” key range=[(9−1+1−1)/2]−3.5=0.5.Thus, the potential insertion of “Albert Lea” into the RRN “6” impactsthe RRN density of the “Austin” key range by reducing the number ofdeleted rows in the “Austin” key range by one and impacts the RRNdensity by increasing the RRN density by 0.5. The potential insertion of“Albert Lea” into RRN “6” on the “Byron” and “Stewartville” key rangesimpacts their RRN densities by zero because the RRN “6” is outside ofthe “Byron” and “Stewartville” key ranges (the key ranges of “Byron” and“Stewartville” do not overlap the key range of “Albert Lea”), so theDBMS 150 adds zero to 0.5, to yield a sum of 0.5, as the sum of theimpacts on the RRN density, of the potential insertion of the receivedkey value at RRN 446: 9

Using the example of FIGS. 7 and 8, the DBMS 150 calculates the impactof potentially inserting the received key of “Albert Lea” into thecandidate row of RRN “8” as the potential RRN density of the “Austin”key range, as impacted by the potential insertion at RRN “8” minus thecurrent RRN density 820 of the “Austin” key range (entry 830)=(last RRNof the “Austin” key range−first RRN of the “Austin” key range+1−deletedcount of the “Austin” key range)/(key count of the “Austin” keyrange)−the current density of the “Austin” keyrange=[(9−1+1−1)/2]−3.5=0.5. Thus, the potential insertion of “AlbertLea” into the RRN “8” impacts the RRN density of the “Austin” key rangeby reducing the number of deleted rows in the “Austin” key range by oneand impacts the RRN density by increasing the RRN density by 0.5. Thepotential insertion of “Albert Lea” into RRN “8” on the “Byron” and“Stewartville” key ranges impacts their RRN densities by zero becausethe RRN “8” is outside of the “Byron” and “Stewartville” key ranges, sothe DBMS 150 adds zero to 0.5, to yield a sum of 0.5, as the sum of theimpacts on the RRN density, of the potential insertion of the receivedkey value at RRN “8.”

Using the example of FIGS. 7 and 8, the DBMS 150 calculates the impactof potentially inserting the received key of “Albert Lea” into thecandidate row of RRN “10” as zero because the RRN “10” is outside thekey ranges of “Austin,” “Byron,” and “Stewartville,” the potentialinsertion at RRN “10” does not change the first RRN, the last RRN, thedeleted count, or the key count of any of the key ranges, and the sum ofthe zero impacts is zero.

Using the example of FIGS. 7 and 8, the DBMS 150 calculates the impactof potentially inserting the received key of “Albert Lea” into thecandidate row of RRN “10” as the sum of the impacts on the RRN densityof the “Bryon” key range and the “Stewartville” key range.

The impact on the “Byron” key range is the potential RRN density of the“Byron” key range, as impacted by the potential insertion at RRN “10”minus the current RRN density 820 of the “Byron” key range (entry834)=(last RRN of the “Byron” key range−first RRN of the “Byron” keyrange+1−deleted count of the “Byron” key range)/(key count of the“Byron” key range)−the current density of the “Byron” keyrange=[(20−11+1−1)/4]−2=0.25. Thus, the potential insertion of “AlbertLea” into the RRN “10” impacts the RRN density of the “Byron” key rangeby reducing the number of deleted rows in the “Byron” key range by oneand impacts the RRN density by increasing the RRN density by 0.25.

The impact on the “Stewartville” key range is the potential RRN densityof the “Stewartville” key range, as impacted by the potential insertionat RRN “10” minus the current RRN density 820 of the “Stewartville” keyrange (entry 836)=(last RRN of the “Stewartville” key range−first RRN ofthe “Stewartville” key range+1−deleted count of the “Stewartville” keyrange)/(key count of the “Stewartville” key range)−the current densityof the “Stewartville” key range=[(19−17+1−0)/2]−1=0.5. Thus, thepotential insertion of “Albert Lea” into the RRN “10” impacts the RRNdensity of the “Stewartville” key range by reducing the number ofdeleted rows in the “Stewartville” key range by one and impacts the RRNdensity by increasing the RRN density by 0.5.

The potential insertion of “Albert Lea” into RRN “10” on the “Austin”key ranges impacts its RRN density by zero because the RRN “10” isoutside of the “Austin” key range, so the DBMS 150 adds 0.25+0.5+0, toyield a sum of all the impacts of 0.75, of the potential insertion ofthe received key value at RRN “10.”

Thus, the DBMS 150 has calculated a set of sums of RRN densityimpacts=(0.5 for RRN “6”, 0.5 for RRN “8”, 0 for RRN “10”, 0.75 for RRN“14”). The DBMS 150 then selects the smallest or least of the set ofsums, which is 0 for RRN “10” and inserts the received key value of“Albert Lea” into the selected row at RRN “10.”

FIG. 10 depicts a block diagram of an example data structure for asymbol table 260-5 after insertion of a value into the database 230-3(FIG. 9), according to an embodiment of the invention. The symbol table260-5 comprises entries 1030, 1032, 1034, and 1036, each of whichcomprises a key value field 1000, a first RRN field 1012, a last RRNfield 1014, a deleted count field 1016, a key count field 1018, and anRRN density field 1020. The DBMS 150 updated the deleted count 1016 inthe entry 1032 to reflect that the row at RRN “10” is no longer deletedin the database 230-3 (FIG. 9).

FIG. 11 depicts a flowchart of example processing for an insert orupdate command, according to an embodiment of the invention. Controlbegins at block 1100. Control then continues to block 1105 where theDBMS 150 receives, from the application 160, an insert or update command158 that specifies a key, a key value, and a table.

Control then continues to block 1110 where the DBMS 150 selects a symboltable from among all of the symbol tables 260 based on the receivedinsert or update command 158 and an index in the database that comprisesthe table. In an embodiment, if the insert or update command 158specifies two or more keys or columns in the same table that have amulti-key index over them, then the DBMS 150 selects the symbol tablewith the two or more keys or columns. If the insert or update command158 does not specify two keys or columns in the same table or the twokeys or columns do not have a multi-key index over them, then the DBMS150 selects a single column symbol table that is assigned to the key orcolumn specified by the insert or update command 158. A multi-key indexaccepts, as input, multiple keys and key values and, in response,returns the relative record number of a row that comprises all of thekey values in the identified keys or columns. A single key indexaccepts, as input, only one key and one key value.

Control then continues to block 1115 where the DBMS 150 determineswhether a key range of the received key value(s) has a deleted countthat is greater than zero. In an embodiment, the DBMS 150 makes thedetermination of block 1115 by finding an entry in the selected symboltable 260 with a key value(s) field that matches (is identical to) thekey value specified by the received insert/update command 158 and bydetermining whether the deleted count field, in the same entry of theselected symbol table, specifies a value that is greater than zero.

If the determination at block 1115 is true, then the key range of thereceived key value has a deleted count that is greater than zero (thekey range has at least one deleted row within the range), so controlcontinues to block 1120 where the DBMS 150 finds candidate rows. Invarious embodiments, the candidate rows are all deleted (available) rowswithin the key range of the received key value, a sample of all deletedrows within the key range of the received key value, or all deleted rowsthat are not in the key range of the received key value and that are theclosest to the key range (whose RRNs are within a threshold value of thekey range). Control then continues to block 1125 where the DBMS 150calculates, for each candidate row, the impact of potentially insertingthe received key value into the candidate row on the RRN density of eachof the other key values that are stored within the key range of thereceived key value. The DBMS 150 selects a selected candidate deletedrow, into which the potential insertion causes the function result (invarious embodiments, the function result is an arithmetic or logicalfunction result, such as a sum, a maximum, an arithmetic product, alogarithmic function, or any combination or multiple thereof) of all theimpacts on the calculated RRN densities to increase the least. That is,for each of the candidate rows, the DBMS 150 calculates a functionresult of the respective impacts on the respective RRN densities andselects a selected candidate row with the smallest function result.Thus, the DBMS 150 re-calculates the RRN density in each entry of thesymbol table 260 with the deleted counts and the key counts updated toreflect the insertion of the key value into each deleted row. In anembodiment, the DBMS 150 reduces the number of candidate rows and stopscalculating the impact of potentially inserting the received key valueafter a threshold amount of time has elapsed since the calculationstarted. In various embodiments, the DBMS 150 may receive variousthreshold amounts and/or values from a designer of the DBMS 150, fromthe application 160, from the user I/O device 121, or from the network130.

Control then continues to block 1130 where the DBMS 150 inserts (stores)the key value into the selected candidate deleted row or updates(stores) the key value into a pre-existing non-deleted row and moves theupdated row to the selected candidate deleted row, which causes thepre-existing row to become deleted and causes the candidate deleted rowto no longer be deleted. The DBMS 150 updates the first RRNs, the lastRRNs, the deleted counts and key counts in the symbol table 260 toreflect the insertion at the selected deleted row or to reflect themoving of the updated row to the selected deleted row. The DBMS 150further re-calculates all of the RRN densities in the symbol table 260,using the updated deleted counts and key counts or re-calculates the RRNdensities for key ranges that are impacted by the updated deleted countsand key counts. Control then continues to block 1199 where the logic ofFIG. 11 returns.

If the determination at block 1115 is false, then key range of thereceived key value has a deleted count that is equal to zero (no deletedrows exist in the key range of the received key value), so controlcontinues to block 1135 where the DBMS 150 inserts or stores the keyvalue into a deleted row that is outside of the key range of thereceived key value and that is the closest to the key range (closest tothe last RRN if the deleted row is after the last RRN or closest to thefirst RRN if the deleted row is before the first RRN) and updates thefirst RRN or last RRN of the key range to reflect the new key range thatnow comprises the formerly deleted row or updates the key value in placeand updates the first RRN or last RRN to reflect the new range that nowcomprises the formerly deleted row. The DBMS 150 updates the first RRNs,the last RRNs, the deleted counts and key counts in the symbol table 260to reflect the insertion at the selected deleted row and to reflect themoving of the updated row to the selected deleted row. The DBMS 150further re-calculates all of the RRN densities in the symbol table 260,using the updated deleted counts and key counts. Control then continuesto block 1199 where the logic of FIG. 11 returns.

FIG. 12 depicts a flowchart of example processing for reorganizing adatabase table, according to an embodiment of the invention. In anembodiment, the logic of FIG. 12 executes concurrently, simultaneously,substantially simultaneously, or interleaved with the logic of FIG. 11,in the same or a different thread, task, or process, viamulti-processing, multi-threading, or multi-programming techniques onthe same or different of the processors 101. Control begins at block1200. Control then continues to block 1205 where the DBMS 150 determineswhether a time period has ended or elapsed and/or the processor 101 hasavailable or free cycles not being used for other work. In variousembodiments, the DBMS 150 receives the time period from the user I/Odevice 121 and stores the time period to the memory 102, or the timeperiod is set by the designer of the DBMS 150.

If the determination at block 1205 is true, then a time period has endedor elapsed and/or the processor 101 has available cycles, so controlcontinues to block 1210 where the DBMS 150 searches the symbol table 260and finds the entry representing a key range with a combination of thesmallest RRN density and the largest deleted count, or finds the keyrange entry with the smallest RRN density, or finds the key range entrywith the largest deleted count. The DBMS 150 moves an endpoint row (invarious embodiments, the first key value at the first RRN or the lastkey value at the last RRN) of the found key range to the median deletedrow between the first RRN and the last RRN of the found key range.Control then continues to block 1215 where the DBMS 150 waits for theexpiration of the time period and/or until such time as the processor101 has available cycles. Control then returns to block 1205, aspreviously described above.

If the determination at block 1205 is false, then the time period hasnot ended or elapsed and/or the processor 101 does not have availablecycles, so control continues to block 1215, as previously describedabove.

In this way, in an embodiment, the DBMS 150 increases the density of keyvalues within key ranges, which increases the sequential nature of datastored within a database table, which increases performance by reducingthe amount of time to read data from secondary storage and bring thedata into memory and by reducing the number of times that data must beloaded into memory.

The terminology used herein is for the purpose of describing particularembodiments only and is not intended to be limiting of the invention. Asused herein, the singular forms “a,” “an,” and “the” are intended toinclude the plural forms as well, unless the context clearly indicatesotherwise. It will be further understood that the terms “comprises”and/or “comprising,” when used in this specification, specify thepresence of the stated features, integers, steps, operations, elements,and/or components, but do not preclude the presence or addition of oneor more other features, integers, steps, operations, elements,components, and/or groups thereof. In the previous detailed descriptionof exemplary embodiments of the invention, reference was made to theaccompanying drawings (where like numbers represent like elements),which form a part hereof, and in which is shown by way of illustrationspecific exemplary embodiments in which the invention may be practiced.These embodiments were described in sufficient detail to enable thoseskilled in the art to practice the invention, but other embodiments maybe utilized and logical, mechanical, electrical, and other changes maybe made without departing from the scope of the present invention. Inthe previous description, numerous specific details were set forth toprovide a thorough understanding of embodiments of the invention. But,embodiments of the invention may be practiced without these specificdetails. In other instances, well-known circuits, structures, andtechniques have not been shown in detail in order not to obscureembodiments of the invention.

Different instances of the word “embodiment” as used within thisspecification do not necessarily refer to the same embodiment, but theymay. Any data and data structures illustrated or described herein areexamples only, and in other embodiments, different amounts of data,types of data, fields, numbers and types of fields, field names, numbersand types of rows, records, entries, or organizations of data may beused. In addition, any data may be combined with logic, so that aseparate data structure is not necessary. The previous detaileddescription is, therefore, not to be taken in a limiting sense.

What is claimed is:
 1. A method comprising: receiving a first key value;finding a plurality of candidate rows in a database table, wherein theplurality of candidate rows are deleted; calculating, for the pluralityof candidate rows, a plurality of respective impacts on a plurality ofrespective current densities of each of other key values that are storedwithin a first key range of the first key value; for the plurality ofcandidate rows, calculating a plurality of function results of theplurality of respective impacts on the plurality of respective currentdensities; selecting a selected candidate row of the plurality ofcandidate rows with a smallest function result of the plurality offunction results of the plurality of respective impacts on the pluralityof respective current densities; and storing the first key value to theselected candidate row.
 2. The method of claim 1, wherein the pluralityof candidate rows are selected from a group consisting of: all deletedrows within the first key range of the first key value, a sample of alldeleted rows within the first key range of the first key value, and alldeleted rows that are within a threshold value of the first key range ofthe first key value, and wherein the calculating the plurality offunction results of the plurality of respective impacts on the pluralityof respective current densities further comprises calculating aplurality of sums of the plurality of respective impacts on theplurality of respective current densities.
 3. The method of claim 1,wherein the storing further comprises: updating a non-deleted row withthe first key value; and moving the non-deleted row to the selectedcandidate row.
 4. The method of claim 1, wherein the calculating theplurality of respective impacts comprises calculating potentialdensities of other key ranges minus the plurality of respective currentdensities of the other key ranges, wherein the first key range and theother key ranges overlap.
 5. The method of claim 4, wherein thecalculating the plurality of respective impacts further comprises:calculating ((a respective last relative record number of the other keyranges minus a respective first relative record number of the other keyranges plus one minus a respective deleted count of the other keyranges, as impacted by potential insertion of the first key value)divided by (a respective key count of the other key ranges)) minus theplurality of current densities of the other key ranges.
 6. The method ofclaim 1, further comprising: if the first key range of the first keyvalue does not have any deleted rows, inserting the first key value to adeleted row that is closest to the first key range.
 7. The method ofclaim 1, further comprising: periodically searching for a found keyrange with a smallest density and moving an endpoint row of the foundkey range to a median deleted row within the found key range.
 8. Themethod of claim 1, further comprising: periodically searching for afound key range with a largest deleted count and moving an endpoint rowof the found key range to a median deleted row within the found keyrange.
 9. The method of claim 1, further comprising: performing thecalculating the plurality of respective impacts, the calculating theplurality of function results, the selected the selected candidate row,and the storing the first key value to the selected candidate row if thefirst key range of the first key value comprises at least one deletedrow.
 10. A computer-readable storage medium encoded with instructions,wherein the instruction when executed comprise: receiving a first keyvalue; finding a plurality of candidate rows in a database table,wherein the plurality of candidate rows are deleted; calculating, forthe plurality of candidate rows, a plurality of respective impacts on aplurality of respective current densities of each of other key valuesthat are stored within a first key range of the first key value, whereinthe calculating the plurality of respective impacts comprisescalculating potential densities of other key ranges minus the pluralityof respective current densities of the other key ranges, wherein thefirst key range and the other key ranges overlap; for the plurality ofcandidate rows, calculating a plurality of function results of theplurality of respective impacts on the plurality of respective currentdensities; selecting a selected candidate row of the plurality ofcandidate rows with a smallest function result of the plurality offunction results of the plurality of respective impacts on the pluralityof respective current densities; and storing the first key value to theselected candidate row.
 11. The computer-readable storage medium ofclaim 10, wherein the plurality of candidate rows are selected from agroup consisting of: all deleted rows within the first key range of thefirst key value, a sample of all deleted rows within the first key rangeof the first key value, and all deleted rows that are within a thresholdvalue of the first key range of the first key value, and wherein thecalculating the plurality of function results of the plurality ofrespective impacts on the plurality of respective current densitiesfurther comprises calculating a plurality of sums of the plurality ofrespective impacts on the plurality of respective current densities. 12.The computer-readable storage medium of claim 10, wherein the storingfurther comprises: updating a non-deleted row with the first key value;and moving the non-deleted row to the selected candidate row.
 13. Thecomputer-readable storage medium of claim 10, wherein the calculatingthe plurality of respective impacts further comprises: calculating ((arespective last relative record number of the other key ranges minus arespective first relative record number of the other key ranges plus oneminus a respective deleted count of the other key ranges, as impacted bypotential insertion of the first key value) divided by (a respective keycount of the other key ranges)) minus the plurality of current densitiesof the other key ranges.
 14. The computer-readable storage medium ofclaim 10, further comprising: if the first key range of the first keyvalue does not have any deleted rows, inserting the first key value to adeleted row that is closest to the first key range.
 15. Thecomputer-readable storage medium of claim 10, further comprising:periodically searching for a found key range with a smallest density andmoving an endpoint row of the found key range to a median deleted rowwithin the found key range; periodically searching for a found key rangewith a largest deleted count and moving an endpoint row of the found keyrange to a median deleted row within the found key range; and performingthe calculating the plurality of respective impacts, the calculating theplurality of function results, the selected the selected candidate row,and the storing the first key value to the selected candidate row if thefirst key range of the first key value comprises at least one deletedrow.
 16. A computer comprising: a processor; and memory communicativelycoupled to the processor, wherein the memory is encoded withinstructions, wherein the instructions when executed by the processorcomprise receiving a first key value, finding a plurality of candidaterows in a database table, wherein the plurality of candidate rows aredeleted, calculating, for the plurality of candidate rows, a pluralityof respective impacts on a plurality of respective current densities ofeach of other key values that are stored within a first key range of thefirst key value, wherein the calculating the plurality of respectiveimpacts comprises calculating potential densities of other key rangesminus the plurality of respective current densities of the other keyranges, wherein the first key range and the other key ranges overlap,wherein the calculating the plurality of respective impacts furthercomprises calculating ((a respective last relative record number of theother key ranges minus a respective first relative record number of theother key ranges plus one minus a respective deleted count of the otherkey ranges, as impacted by potential insertion of the first key value)divided by (a respective key count of the other key ranges)) minus theplurality of current densities of the other key ranges, for theplurality of candidate rows, calculating a plurality of function resultsof the plurality of respective impacts on the plurality of respectivecurrent densities, selecting a selected candidate row of the pluralityof candidate rows with a smallest function result of the plurality offunction results of the plurality of respective impacts on the pluralityof respective current densities, and storing the first key value to theselected candidate row.
 17. The computer of claim 16, wherein theplurality of candidate rows are selected from a group consisting of: alldeleted rows within the first key range of the first key value, a sampleof all deleted rows within the first key range of the first key value,and all deleted rows that are within a threshold value of the first keyrange of the first key value, and wherein the calculating the pluralityof function results of the plurality of respective impacts on theplurality of respective current densities further comprises calculatinga plurality of sums of the plurality of respective impacts on theplurality of respective current densities.
 18. The computer of claim 16,wherein the storing further comprises updating a non-deleted row withthe first key value; and moving the non-deleted row to the selectedcandidate row.
 19. The computer of claim 16, wherein the instructionsfurther comprise: if the first key range of the first key value does nothave any deleted rows, inserting the first key value to a deleted rowthat is closest to the first key range.
 20. The computer of claim 16,wherein the instructions further comprise: periodically searching for afound key range with a smallest density and moving an endpoint row ofthe found key range to a median deleted row within the found key range;periodically searching for a found key range with a largest deletedcount and moving an endpoint row of the found key range to a mediandeleted row within the found key range; and performing the calculatingthe plurality of respective impacts, the calculating the plurality offunction results, the selected the selected candidate row, and thestoring the first key value to the selected candidate row if the firstkey range of the first key value comprises at least one deleted row.